<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/sunzbase.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="resources/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<z:resource items="easyui"></z:resource>
<title>添加分类</title>
</head>
<body>
<div class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-category-add">
		<div id="tab-category" class="HuiTab">
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">分类ID：</label>
					<div class="formControls col-xs-8 col-sm-9">${tag.id}</div>
					<input type="hidden" id="classID" name="classID" value="${tag.id}"/>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">
						<span class="c-red">*</span>
						上级分类：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
					<!-- 	<select class="select" id="sel_Sub" name="sel_Sub" onchange="SetSubID(this);"> -->
<!-- 							<option value="0">顶级分类</option>
							<option value="10">分类一级</option>
							<option value="101">&nbsp;&nbsp;├ 分类二级</option>
							<option value="102">&nbsp;&nbsp;├ 分类二级</option>
							<option value="20">分类一级</option>
							<option value="200">&nbsp;&nbsp;├ 分类二级</option> -->
						<!-- </select> -->
						<input id="sel_Sub" style="width:100%" name="sel_Sub"/>
						</span>
					</div>
					<div class="col-3">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">
						<span class="c-red">*</span>
						分类名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" value="${tag.tagName}" placeholder="" id="className" name="className">
					</div>
					<div class="col-3">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">分类排序：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" value="${tag.sequence}" placeholder="" id="sequence" name="sequence">
					</div>
					<div class="col-3">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">备注：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<textarea value="${tag.remark}" name="remark" id="remark" cols="" rows="" class="textarea"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="$.Huitextarealength(this,100)">${tag.remark}</textarea>
					</div>
					<div class="col-3">
					</div>
				</div>
			</div>			
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input id="classSubmit" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="resources/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="resources/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="resources/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	//所有分类
	var id=$("#classID").val();
/* 	$.ajax({
		url:"note/allClass",
		data:{classID:id},
		dataType:"json",
		success:function(result){
			if(result.success){
				var data=result.data;
				$("#sel_Sub").append("<option value='0'>顶级分类</option>");
				for(var i=0;i<data.length;i++){		
					$("#sel_Sub").append("<option value='"+data[i].id+"'>"+data[i].tagName+"</option>");
 					if(id!=""&&id!=null){
						if(id==data[i].id){
							$("#sel_Sub").append("<option selected='true' value='"+result.data.parentClass.id+"'>"+result.data.parentClass.tagName+"</option>");
						}else 
							$("#sel_Sub").append("<option value='"+data[i].id+"'>"+data[i].tagName+"</option>");
					} 	
				}
				if(id!=""&&id!=null){
						$("#sel_Sub").find("option[value='${tag.parentId}']").attr("selected",true);
				}
			}
		},
		error:function(){}
	}); */
	$.ajax({
		url:"note/allClass2",
		data:{classID:id},
		dataType:"json",
		success:function(result){
			if(result.success){
				var data=result.data.classList;
				data=parseTreeJson(data);
				$("#sel_Sub").combotree({
				   data:[{id:"0",text:"顶级分类",children:data}]
				}); 
				if(id!=null&&result.data.parentClass){
					$("#sel_Sub").combotree("setValue",result.data.parentClass.id);
				}else{
					$("#sel_Sub").combotree("setValue",0);
				}
			}
		},
		error:function(){}
	});
	
	function parseTreeJson(data){
		for(var i=0;i<data.length;i++){
			var item=data[i];
			item.text=data[i].tagName;
			item.children=item.childs;
			parseTreeJson(item.children);
		}
		return data;
	}

	
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#tab-category").Huitab({
		index:0
	});
	$("#form-category-add").validate({
		rules:{
			className:{
				required:true
			},
			sequence:{
				//required:true,
				digits:true
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				url:"note/classSubmit",
				type:"POST",
				data:$("form-category-add").serialize(),
				success:function(result){
					if(result.success){
						layer.msg("提交成功！",{icon:6});
					  }else{
						layer.msg("提交失败，请重新提交！");
					  }
					setTimeout(function(){
						var index = parent.layer.getFrameIndex(window.name);
						parent.$('#btnSearch').click();
						parent.layer.close(index);
					},1000);
				}
			});
		}
	});
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>